/*
 * ONSThread.java
 *
 * Created on June 6, 2010, 7:21 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package orajdbcstat;

import oracle.ons.*;
import java.util.*;
import java.io.*;
import java.nio.*;

/**
 *
 * @author vnull
 */
public class ONSThread implements Runnable{
    private Configuration conf;
    /** Creates a new instance of ONSThread */
    public ONSThread(Configuration conf) {
        this.conf = conf;
    }
    
    public void run() {
        Subscriber s = new Subscriber("", ""); // subscribe to all events
        Notification n;
        
        if(conf.ONSConfiguration == null || conf.ONSConfiguration.equals("")) {
            return;
        }
        
        if(conf.verbose >= 2) {
            System.out.println("ONS subscriber starting");
        }
        
        while (true) {
            // blocking wait for notification receive
            n = s.receive(true);
            
            if(conf.verbose >= 1) {
                System.err.println("*** FAN event received: " + n.generatingComponent() + "@" + n.generatingProcess());
            }

            
            try {
                java.lang.Thread.currentThread().sleep(1);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
